package com.platform.modules.mall.activity.rule;

import com.platform.common.exception.BusinessException;
import com.platform.common.utils.StringUtils;
import com.platform.modules.mall.entity.MallGoodsToActivityEntity;

import java.util.Iterator;
import java.util.List;

public class DirectGoodsUtil extends RuleAbstract{

    private String goodsId;

    public DirectGoodsUtil(List<MallGoodsToActivityEntity> list, String goodsId) {
        super(list);
        if (StringUtils.isBlank(goodsId)){
            throw new BusinessException("商品id不能为空");
        }
        this.goodsId=goodsId;
    }

    @Override
    public MallGoodsToActivityEntity getEntity() {
        Iterator<MallGoodsToActivityEntity> iterator = entityList.iterator();
        while (iterator.hasNext()){
            MallGoodsToActivityEntity goods = iterator.next();
            if (goods.getGoodsId().equals(this.goodsId)){
                return goods;
            }
        }
        return null;
    }
}
